package Road;

import java.util.Scanner;

/**
 * create by Sun
 * 2018/8/23
 */
public class Dijkstra {
    static int n;
    static final Integer max=Integer.MAX_VALUE;
//static final Integer max=333333;
    static int[][] map=new int[1000][1000];
    static int[][] cost=new int[1000][1000];
    static int[] dis=new int[1000];
    static int[] money=new int[1000];
    static int[] vis=new int[1000];


    private static void dijikstra(int s) {
        for(int i=0;i<n;i++){
            dis[i]=map[s][i];
            money[i]=cost[s][i];
        }
        vis[s]=1;
        for(int l=1;l<n;l++) {
            int min = max;
            int k=s;
            for (int j = 0; j < n; j++) {
                if (dis[j] < min && vis[j] == 0) {
                    min = dis[j];
                    k = j;
                }
            }
            vis[k] = 1;

            for (int j = 0; j < n; j++) {
                //&&map[k][j]<max,整数值的越界问题  ，，之前这里出现问题
                if (vis[j] == 0&&map[k][j]<max) {
                    if (dis[j] > map[k][j] + dis[k]) {
                        dis[j] = map[k][j] + dis[k];
                        money[j] = cost[k][j] + money[k];
                    }
                    else if (dis[j] == map[k][j] + dis[k]) {
                        if (money[j] > cost[k][j] + money[k]) {
                            money[j] = cost[k][j] + money[k];
                        }
                    }
                }
            }
        }
    }


    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while (t--!=0){
            n=sc.nextInt();
            int m=sc.nextInt();
            int s=sc.nextInt();
            int k=sc.nextInt();
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(i==j){
                        map[i][j]=0;
                        cost[i][j]=0;
                    }else {
                        map[i][j]=map[j][i]=max;
                        cost[i][j]=cost[j][i]=max;
                    }
                }
            }
            for(int i=0;i<m;i++){
                int a=sc.nextInt();
                int b=sc.nextInt();
                int c=sc.nextInt();
                int d=sc.nextInt();

                map[a][b]=map[b][a]=c;
                cost[a][b]=cost[b][a]=d;
            }
            dijikstra(s);
            System.out.println(dis[k]+" "+money[k]);
        }
    }


}
